Handle disabled agents better in dot_helper

Glenn 'devalias' Grant 11 anni fa
parent
commit
68c5854796
1 ha cambiato i file con 7 aggiunte e 11 eliminazioni
  1. 7 11
      app/helpers/dot_helper.rb

+ 7 - 11
app/helpers/dot_helper.rb

@@ -22,24 +22,20 @@ module DotHelper
22 22
     '"%s"' % string.gsub(/\\/, "\\\\\\\\").gsub(/"/, "\\\\\"")
23 23
   end
24 24
 
25
+  def disabled_label(agent)
26
+    agent.disabled? ? dot_id(agent.name + " (Disabled)") : dot_id(agent.name)
27
+  end
28
+
25 29
   def agents_dot(agents, rich = false)
26 30
     "digraph foo {".tap { |dot|
27 31
       agents.each.with_index do |agent, index|
28 32
         if rich
29
-          if agent.disabled
30
-            dot << '%s[URL=%s] (Disabled);' % [dot_id(agent.name), dot_id(agent_path(agent.id))]
31
-          else
32
-            dot << '%s[URL=%s];' % [dot_id(agent.name), dot_id(agent_path(agent.id))]
33
-          end
33
+          dot << '%s[URL=%s];' % [disabled_label(agent), dot_id(agent_path(agent.id))]
34 34
         else
35
-          if agent.disabled
36
-            dot << '%s (Disabled);' % dot_id(agent.name)
37
-          else
38
-            dot << '%s;' % dot_id(agent.name)
39
-          end
35
+          dot << '%s;' % disabled_label(agent)
40 36
         end
41 37
         agent.receivers.each do |receiver|
42
-          dot << "%s->%s;" % [dot_id(agent.name), dot_id(receiver.name)]
38
+          dot << "%s->%s;" % [disabled_label(agent), disabled_label(receiver)]
43 39
         end
44 40
       end
45 41
       dot << "}"